#include <unordered_set>
#include <algorithm>
#include <cstdio>

constexpr int MAXN = 400000 + 2;

int tot;

long long val[MAXN], d[MAXN];

std::unordered_set<int> st;

template <typename T> class FenwickTree {
  public:
    T t[MAXN];

    void add(int x, T k) {
        for (; x <= tot; x += x & -x) {
            t[x] += k;
        }
    }

    T query(int x) {
        T ret = 0;
        for (; x; x &= x - 1) {
            ret += t[x];
        }
        return ret;
    }
};

FenwickTree<int> rnkTree;
FenwickTree<long long> sumTree;

int getPos(int x) {
    int rnk = 0, o = 0;

    for (int i = std::__lg(tot); i >= 0; i --) {
        int nxt = o | 1 << i;
        if (nxt <= tot && rnk + rnkTree.t[nxt] < x) {
            rnk += rnkTree.t[o = nxt];
        }
    }

    return o + 1;
}

class SegmentTree {
  public:
    __int128 t[MAXN << 2];

    long long sum[MAXN << 2];

    int tag[MAXN << 2];

#define ls(o) o << 1
#define rs(o) o << 1 | 1

    void push(int o, int tg) {
        t[o] += sum[o] * tg;
        tag[o] += tg;
    }

    void pushDown(int o) {
        if (!tag[o]) {
            return;
        }
        push(ls(o), tag[o]);
        push(rs(o), tag[o]);
        tag[o] = 0;
    }

    void pushUp(int o) {
        t[o] = t[ls(o)] + t[rs(o)];
        sum[o] = sum[ls(o)] + sum[rs(o)];
    }

    void add(int x, long long v1, long long v2) {
        int o = 1, l = 1, r = tot;
        t[o] += v1;
        sum[o] += v2;

        while (l < r) {
            pushDown(o);

            int mid = (l + r) >> 1;
            if (x <= mid) {
                o = ls(o);
                r = mid;
            } else {
                o = rs(o);
                l = mid + 1;
            }

            t[o] += v1;
            sum[o] += v2;
        }
    }

    void add(int x, int v) {
        int o = 1, l = 1, r = tot;

        while (l < r) {
            pushDown(o);

            int mid = (l + r) >> 1;
            if (x <= mid) {
                push(rs(o), v);
                o = ls(o);
                r = mid;
            } else {
                o = rs(o);
                l = mid + 1;
            }
        }

        push(o, v);
        while (o >>= 1) {
            pushUp(o);
        }
    }

    long long totSum() {
        return sum[1];
    }

    __int128 querySumI(int o, int l, int r, int x, int y) {
        if (x <= l && r <= y) {
            return t[o];
        }
        pushDown(o);

        int mid = (l + r) >> 1;
        if (y <= mid) {
            return querySumI(ls(o), l, mid, x, y);
        }
        if (x > mid) {
            return querySumI(rs(o), mid + 1, r, x, y);
        }
        return querySumI(ls(o), l, mid, x, y)
             + querySumI(rs(o), mid + 1, r, x, y);
    }

    __int128 querySumI(int l, int r) {
        if (l > r) {
            return 0;
        }
        if (l > 1) {
            l = getPos(l);
        }
        if (r < tot) {
            r = getPos(r);
        }
        return querySumI(1, 1, tot, l, r);
    }

#undef ls
#undef rs

} sumITree;

long long preSum(int x) {
    long long ret = 0;
    int rnk = 0, o = 0;

    for (int i = std::__lg(tot); i >= 0; i --) {
        int nxt = o | 1 << i;
        if (nxt <= tot && rnk + rnkTree.t[nxt] < x) {
            rnk += rnkTree.t[o = nxt];
            ret += sumTree.t[o];
        }
    }

    return ret + d[o + 1];
}

long long sufSum(int x) {
    return sumITree.totSum() - preSum(x - 1);
}

int main() {
    freopen("kte.in", "r", stdin);
    freopen("kte.out", "w", stdout);

    int T;
    scanf("%d", &T);

    for (int i = 1; i <= T; i ++) {
        scanf("%lld", &val[i]);
        d[i] = val[i];
    }

    std::sort(d + 1, d + T + 1);
    tot = std::unique(d + 1, d + T + 1) - d - 1;

    for (int i = 1; i <= T; i ++) {
        int v = std::lower_bound(
          d + 1, d + tot + 1, val[i]
        ) - d;

        if (st.count(v)) {
            st.erase(v);

            sumITree.add(v, -d[v] * rnkTree.query(v), -d[v]);
            sumITree.add(v, -1);

            rnkTree.add(v, -1);
            sumTree.add(v, -d[v]);
        } else {
            st.insert(v);

            sumITree.add(v, d[v] * rnkTree.query(v), d[v]);
            sumITree.add(v, 1);

            rnkTree.add(v, 1);
            sumTree.add(v, d[v]);
        }

        int n = st.size();
        int l = 0, r = n >> 1;

        if (n < 2) {
            puts("0");
            continue;
        }

        while (l < r) {
            int mid = (l + r + 1) >> 1;
            if (preSum(mid + 1) >= sufSum(n - mid + 1)) {
                l = mid;
            } else {
                r = mid - 1;
            }
        }

        long long ans = (__int128){l + 2} * preSum(l + 1)
                      + (__int128){n - l} * sufSum(n - l + 1)
                      - sumITree.querySumI(1, l + 1)
                      - (l ? sumITree.querySumI(n - l + 1, tot) : 0);
        l = (n >> 1) + 1;
        r = n - 1;

        while (l < r) {
            int mid = (l + r) >> 1;
            if (preSum(mid + 1) >= sufSum(n - mid + 1)) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }

        if (n > 2) {
            ans += (__int128){n + 1} * sufSum(l + 1)
                 + (__int128){n - l} * (preSum(l) - sufSum(n - l + 2))
                 + preSum(n - l + 1)
                 - sumITree.querySumI(l + 1, tot)
                 - sumITree.querySumI(1, n - l + 1);
        }

        printf("%lld\n", sumITree.totSum() - ans);
    }

    return 0;
}
